using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Notes : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    private string userID;
    string yeni;
    protected void Page_Load(object sender, EventArgs e)
    {

        userID = Session["UserID"].ToString();

        ds = workLayerWeb.GetRecurrenceTypes(userID);

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            
                ddlRecurrenceTypes.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());

        }


        ds = workLayerWeb.FillNotes(userID);

        dgvNotes.DataSource = ds;
        dgvNotes.DataBind();

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (i < dgvNotes.Rows.Count)
            {
                dgvNotes.Rows[i].ID = ds.Tables[0].Rows[i].ItemArray[ds.Tables[0].Columns.Count - 1].ToString();
                //ddlRecurrenceTypes.Items.Add(ds.Tables[0].Rows[i].ItemArray[3].ToString());
            }
        }


        if (!IsPostBack)
        {
            ddlPriority.Items.Add("1");
            ddlPriority.Items.Add("2");
            ddlPriority.Items.Add("3");
            ddlPriority.Items.Add("4");
            ddlPriority.Items.Add("5");
            ddlPriority.Items.Add("6");
        }

    }
  


    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("GeneralCalendar.aspx");
    }
    protected void btnAddNote_Click(object sender, EventArgs e)
    {

        if(txtNotesTopic.Text!=""){
            if (txtRecurrencenumber.Text.Trim()=="" && txtCalendar.Text.Trim()=="")
            {
                ds = workLayerWeb.AddNotes(txtNotesTopic.Text.Trim(), txtDetailNotes.Text.Trim(), ddlPriority.Text.Trim(), userID);
            }
            else
            {
                ds = workLayerWeb.AddRecurrenceNotes(txtNotesTopic.Text.Trim(), txtDetailNotes.Text.Trim(), ddlPriority.Text.Trim(),
                                            ddlRecurrenceTypes.Text.Trim(), txtRecurrencenumber.Text.Trim(),
                                            txtCalendar.Text, txtEndDate.Text, userID);
            }

            ds = workLayerWeb.FillNotes(userID);

            dgvNotes.DataSource = ds;
            dgvNotes.DataBind();

        }
    }

    protected void dgvNotes_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string NotesID = dgvNotes.Rows[e.RowIndex].ID;

        if (workLayerWeb.DeleteNote(NotesID, Session["UserID"].ToString()))
        {
            this.Page_Load(sender, e);
        }
    }




    /*protected void chbIsnumberofRecurrence_CheckedChanged(object sender, EventArgs e)
    {

        if (chbIsnumberofRecurrence.Checked == true)
        {
            chbIsRecurrenceTimeInterval.Checked = false;
            txtCalendar.Enabled = false;
            txtEndDate.Enabled = false;
        }
        else
        {
            txtCalendar.Enabled = true;
            txtEndDate.Enabled = true;
        }
    }*/
      protected void chbIsNumber_CheckedChanged(object sender, EventArgs e)
    {
        if (chbIsnumber.Checked == true)
        {
            chbIsInterval.Checked = false;
            txtCalendar.Enabled = false;
            txtEndDate.Enabled = false;
        }
        else 
        {
            txtCalendar.Enabled = true;
            txtEndDate.Enabled = true;
        }
    }
    /*
    protected void chbIsRecurrenceTimeInterval_CheckedChanged(object sender, EventArgs e)
    {

        if (chbIsRecurrenceTimeInterval.Checked == true)
        {
            chbIsnumberofRecurrence.Checked = false;
            txtnumberofRecurrence.Enabled = false;
        }
        else
        {
            txtnumberofRecurrence.Enabled = true;
        }


    }*/
    protected void chbIsRecurrenceTimeInterval_CheckedChanged(object sender, EventArgs e)
    {
        if (chbIsInterval.Checked == true)
        {
            chbIsnumber.Checked = false;
            txtRecurrencenumber.Enabled = false;
        }
        else
        {
            txtRecurrencenumber.Enabled = true;
        }
    }


    protected void ddlRecurrenceType_changed(object sender, EventArgs e)
    {
        
    }
}
